home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13166 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!txwang
  2. From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Inheritance problem...and other stuff
  5. Date: Sun, 24 Mar 1996 10:54:27 GMT
  6. Message-ID: <199603232309.HAA23168@public1.guangzhou.gd.cn>
  7. X-NNTP-Posting-Host: txwang
  8. X-Newsreader: Forte Free Agent 1.0.82
  9. X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
  10.  
  11. On 23 Mar 1996 14:49:22 GMT, grantp@usa.pipeline.com(Pete Grant)
  12. wrote:
  13.  
  14. | On Mar 23, 1996 09:01:07 in article <Inheritance problem...and other
  15. | stuff>, 'pcgpe@ix.netcom.com(Mark Feldman)' wrote: 
  16. |  
  17. | >2nd Question: 
  18. | > 
  19. | >What's the standard way of storing such an array to a file and 
  20. | >retrieving it? I could always assign an ID number to each class type 
  21. | >and load them using case statements but this seems messy. I notice that 
  22. | >MFC and OWL seem to use tables to handle the dispatching of windows 
  23. | >messages. Would it be feasable to use this for saving the array info to 
  24. | >a file? Idealy I would like each function to inherit a serialization 
  25. | >function which they can overload to save and restore their data, but 
  26. | >how can I make the loading routine know what type of class to create in 
  27. | >the first place while still keeping the code tight and clean? 
  28. | > 
  29. | There's only one way:  store the type information in the file.  An 
  30. | enum is probably best; alternately, a name string would work also. 
  31. | When you read the data back in, you must check the type info and 
  32. | create an object of appropriate type. 
  33. |  
  34. | There are standard idioms (Coplien's book, for example) for simulating 
  35. | virtual constructors -- I have mixed feelings of those since they 
  36. | are just a thin veil for hiding what you are really doing.  There's 
  37. | really no such thing as a virtual constructor in C++ and I feel a bit 
  38. | uneasy with idioms that try to make it look like they exist.  But 
  39. | at the same time, I can see the benefits also. 
  40.  
  41. In Borland C++, there is a Streamable Class hierarchy, which does what
  42. Mark wants and even more.  Search TStreamable in the online help.
  43.  
  44. ---
  45. Wang TianXing
  46.  
  47.  
  48.